package application.controller;

import java.util.ArrayList;
import java.util.HashMap;
import application.form.Contact;
import application.service.EntityAccomplishmentService;
import application.service.EntitySearchResultsService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
@SessionAttributes
public class ContactController {

        @Autowired
        private EntityAccomplishmentService entityAccomplishmentService;

        @Autowired
        private EntitySearchResultsService entitySearchResultsService;

	@RequestMapping(value = "/addContact", method = RequestMethod.POST)
	public String addContact(@ModelAttribute("contact") Contact contact, BindingResult result) {
/*
		System.out.println("First Name:" + contact.getFirstname() +
					"Last Name:" + contact.getLastname());

*/
		return "redirect:contacts.html";
	}

	@RequestMapping(value = "/contacts", method = RequestMethod.GET)
	public ModelAndView showContacts() {

            HashMap<String,String> article = new HashMap<String,String>();
            ArrayList articles = new ArrayList();

            article.put("articleId", "One");
            article.put("articleName", "One");
            article.put("articleDesc", "One");
            article.put("addedDate", "One");

            articles.add(article);

            //Collection<SynonymsCheckBox> searchTerm1Synonyms = createSelectList();

	    return new ModelAndView("contact", "command", new Contact()).addObject("articles", articles);
	}

        @RequestMapping(value="/contacts", method = RequestMethod.POST)
	public ModelAndView showContacts2(@ModelAttribute("contact") Contact contact, BindingResult result) {

            HashMap<String,String> article = new HashMap<String,String>();
            ArrayList articles = new ArrayList();
/*
            article.put("articleId", contact.getEmail());
            article.put("articleName", contact.getFirstname());
            article.put("articleDesc", contact.getLastname());
            article.put("addedDate", contact.getTelephone());
*/
            articles.add(article);
            //Collection<SynonymsCheckBox> synonymsCheckBox1 = createSelectList();

            //System.out.println("*********** CheckBoxes are: "+contact.getSearchTerm1Synonyms().toString());

            //System.out.println("******* THE SIZE IS: "+entityAccomplishmentService.listSelectedEntityAccomp(contact.getFirstname()).size());
            //System.out.println("******* THE SIZE IS 2: "+entitySearchResultsService.listSelectedEntitySearchResults(contact.getFirstname()).size());

	    return new ModelAndView("contact", "command", new Contact()).addObject("articles", articles).addObject("searchresults", entitySearchResultsService.listSelectedEntitySearchResults(contact.getSearchTerm1()));
            //return new ModelAndView("contact", "command", new Contact()).addObject("entityAccomp", entityAccomplishmentService.listSelectedEntityAccomp());
	}

        /*Test*/
        
        @ModelAttribute("searchOperatorValues")
        public List<String> getSearchOperatorValues() {
                List<String> soValues = new ArrayList<String>();
                soValues.add("None");
                soValues.add("AND");
                soValues.add("OR");
                return soValues;
        }
        
        @ModelAttribute("searchTypeRadioBValues")
        public List<String> getSearchTypeRadioBValues() {
                List<String> stValues = new ArrayList<String>();
                stValues.add("Term");
                stValues.add("Entity");                
                return stValues;
        }

}
